package org.tis.tools.abf.module.ac.controller;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.tis.tools.abf.module.ac.controller.request.AcDeleteListRequest;
import org.tis.tools.abf.module.ac.controller.request.AcFuncAttrRequest;
import org.tis.tools.abf.module.ac.controller.request.AcFuncAttrUpdateRequest;
import org.tis.tools.abf.module.ac.entity.AcFuncAttr;
import org.tis.tools.abf.module.ac.service.IAcFuncAttrService;
import org.tis.tools.core.web.controller.BaseController;
import org.tis.tools.core.web.vo.SmartPage;
import org.tis.tools.model.common.ResultVO;
import org.tis.tools.model.log.enums.OperateType;
import org.tis.tools.starter.operatelog.annotation.OperateLog;

import javax.validation.constraints.NotBlank;

/**
 * acFuncAttr的Controller类
 *
 * @author Auto Generate Tools
 * @date 2018/04/23
 */
@RestController
@RequestMapping("/acFuncAttr")
@Validated
@Slf4j
public class AcFuncAttrController extends BaseController<AcFuncAttr>  {

    @Autowired
    private IAcFuncAttrService acFuncAttrService;


    @ApiOperation(value = "新增功能属性",notes = "传入AcFuncAttrRequest类作为参数")
    @OperateLog(type = OperateType.ADD,desc = "新增功能属性")
    @PostMapping
    public ResultVO add(@RequestBody @Validated @ApiParam(value = "acFuncAttr",name = "传入的AcFuncAttrRequest类",required = true) AcFuncAttrRequest acFuncAttr) {
        acFuncAttrService.creatFuncAttr(acFuncAttr.getGuidFunc(),acFuncAttr.getAttrType(),acFuncAttr.getAttrKey(),acFuncAttr.getAttrValue(),acFuncAttr.getMemo());
        return ResultVO.success("新增成功！");
    }

    @ApiOperation(value = "修改功能属性",notes = "传入AcFuncAttrUpdateRequest作为参数")
    @OperateLog(type = OperateType.UPDATE,desc = "修改功能属性")
    @PutMapping
    public ResultVO update(@RequestBody @Validated  @ApiParam(value = "acFuncAttr",name = "传的AcFuncAttrUpdateRequest",required = true) AcFuncAttrUpdateRequest acFuncAttr) {
        AcFuncAttr acFuncAttr1 = acFuncAttrService.selectById(acFuncAttr.getGuid());
        if (acFuncAttr1 == null) {
            return ResultVO.error("404", "找不到对应记录或已经被删除！");
        }
        AcFuncAttr acFuncAttr2 = acFuncAttrService.changeFuncAttr(acFuncAttr.getGuid(),acFuncAttr.getGuidFunc(),acFuncAttr.getAttrType(),acFuncAttr.getAttrKey(),acFuncAttr.getAttrValue(),acFuncAttr.getMemo());
        return ResultVO.success("修改成功！",acFuncAttr2);
    }


    @ApiOperation(value = "删除功能属性",notes = "传入功能属性的GUID为参数")
    @OperateLog(type = OperateType.DELETE,desc = "删除功能属性")
    @DeleteMapping("/{id}")
    public ResultVO delete(@PathVariable @NotBlank(message = "id不能为空") @ApiParam(value = "id",name = "功能属性的GUID",required = true) String id) {

        AcFuncAttr acFuncAttr = acFuncAttrService.selectById(id);
        if (acFuncAttr == null) {
            return ResultVO.error("404", "找不到对应记录或已经被删除！");
        }

        acFuncAttrService.deleteById(id);
        return ResultVO.success("删除成功!");
    }


    @ApiOperation(value = "批量删除功能属性",notes = "传入AcDeleteListRequest类作为参数")
    @OperateLog(type = OperateType.DELETE,desc = "批量删除功能属性")
    @PostMapping("/batchDelete")
    public ResultVO batchDelete(@RequestBody @Validated @ApiParam(value = "listRequest",name = "传入的AcDeleteListRequest类",required = true) AcDeleteListRequest listRequest) {

        acFuncAttrService.batchDelete(listRequest);
        return ResultVO.success("删除成功!");
    }


    @ApiOperation(value = "根据ID查询功能属性",notes = "传入功能属性的GUID作为参数")
    @GetMapping("/{id}")
    public ResultVO detail(@PathVariable @NotBlank(message = "id不能为空") @ApiParam(value = "id",name = "功能属性的GUID",required = true) String id) {
        AcFuncAttr acFuncAttr = acFuncAttrService.selectById(id);
        if (acFuncAttr == null) {
            return ResultVO.error("404", "找不到对应记录或已经被删除！");
        }
        return ResultVO.success("查询成功", acFuncAttr);
    }

    @ApiOperation(value = "分页查询功能属性",notes = "传入分页数据(page,condition)作为参数")
    @PostMapping("/list/{id}")
    public ResultVO list(@RequestBody @Validated @ApiParam(value = "page",name = "需要传入的page和condition",required = true) SmartPage<AcFuncAttr> page,@PathVariable @NotBlank(message = "id不能为空") @ApiParam(value = "id",name = "功能属性的GUID",required = true) String id) {
        return  ResultVO.success("查询成功", acFuncAttrService.queryPageById(page.getPageObj(), page.getConditionWrapper(),id));
    }

    /** 下面为 行为接口 */

    @ApiOperation(value = "新增行为属性",notes = "传入AcFuncAttrRequest类作为参数")
    @OperateLog(type = OperateType.ADD,desc = "新增行为属性")
    @PostMapping("/addBehave")
    public ResultVO addBehave(@RequestBody @Validated @ApiParam(value = "acFuncAttr",name = "传入的AcFuncAttrRequest类",required = true) AcFuncAttrRequest acFuncAttr) {
        acFuncAttrService.creatFuncAttr(acFuncAttr.getGuidFunc(),acFuncAttr.getAttrType(),acFuncAttr.getAttrKey(),acFuncAttr.getAttrValue(),acFuncAttr.getMemo());
        return ResultVO.success("新增成功！");
    }

    @ApiOperation(value = "修改行为属性",notes = "传入AcFuncAttrUpdateRequest作为参数")
    @OperateLog(type = OperateType.UPDATE,desc = "修改行为属性")
    @PutMapping("/updateBehave")
    public ResultVO updateBehave(@RequestBody @Validated  @ApiParam(value = "acFuncAttr",name = "传的AcFuncAttrUpdateRequest",required = true) AcFuncAttrUpdateRequest acFuncAttr) {
        AcFuncAttr acFuncAttr1 = acFuncAttrService.selectById(acFuncAttr.getGuid());
        if (acFuncAttr1 == null) {
            return ResultVO.error("404", "找不到对应记录或已经被删除！");
        }
        AcFuncAttr acFuncAttr2 = acFuncAttrService.changeFuncAttr(acFuncAttr.getGuid(),acFuncAttr.getGuidFunc(),acFuncAttr.getAttrType(),acFuncAttr.getAttrKey(),acFuncAttr.getAttrValue(),acFuncAttr.getMemo());
        return ResultVO.success("修改成功！",acFuncAttr2);
    }


    @ApiOperation(value = "删除行为属性",notes = "传入行为属性的GUID为参数")
    @OperateLog(type = OperateType.DELETE,desc = "删除行为属性")
    @DeleteMapping("/{id}/behave")
    public ResultVO deleteBehave(@PathVariable @NotBlank(message = "id不能为空") @ApiParam(value = "id",name = "功能属性的GUID",
            required = true) String id) {

        AcFuncAttr acFuncAttr = acFuncAttrService.selectById(id);
        if (acFuncAttr == null) {
            return ResultVO.error("404", "找不到对应记录或已经被删除！");
        }

        acFuncAttrService.deleteById(id);
        return ResultVO.success("删除成功!");
    }


    @ApiOperation(value = "批量删除行为属性",notes = "传入AcDeleteListRequest类作为参数")
    @OperateLog(type = OperateType.DELETE,desc = "批量删除行为属性")
    @PostMapping("/batchDeleteBehave")
    public ResultVO batchDeleteBehave(@RequestBody @Validated @ApiParam(value = "listRequest",name = "传入的AcDeleteListRequest类",required = true) AcDeleteListRequest listRequest) {

        acFuncAttrService.batchDelete(listRequest);
        return ResultVO.success("删除成功!");
    }

    @ApiOperation(value = "分页查询行为属性",notes = "传入分页数据(page,condition)作为参数")
    @PostMapping("/{id}/behaveList")
    public ResultVO behaveList(@RequestBody @Validated @ApiParam(value = "page",name = "需要传入的page和condition",required = true) SmartPage<AcFuncAttr> page,@PathVariable @NotBlank(message = "id不能为空") @ApiParam(value = "id",name = "功能属性的GUID",required = true) String id) {
        return  ResultVO.success("查询成功", acFuncAttrService.queryPageById(page.getPageObj(), page.getConditionWrapper(),id));
    }

}

